package com.invengo.library_rfid;

import com.invengo.device.DeviceHelper;
import com.invengo.library_rfid.analyze.EPCAnalyzeFactory;
import com.invengo.library_rfid.analyze.EPCStrategy;
import com.invengo.library_rfid.analyze._EpcRuleTag;
import com.invengo.library_rfid.classify.AnalyzeImpl;
import com.invengo.library_rfid.classify.RfidModelImpl;

import java.util.HashMap;

import me.goldze.mvvmhabit.utils.KLog;

public class RFIDTestUtils {

    private static HashMap<String, converBean> benbu = new HashMap<String, converBean>() {{
        //层架
        put("C20063012012F66804580805", new converBean("EB030BD6DB6DB6DD", "B8000002"));
        //图书
        put("C200630120131B1E655C0805", new converBean("EA0307D6DB6DB6DC", "A8000001"));
    }};


    private static HashMap<String, converBean> RULE_Default = new HashMap<String, converBean>() {{
        //番禺图书数据
//        put("0088102BC12013160030E176", new converBean("C2003C00200026D196F50005", "A1269877"));
//        put("0088102BC12013160030E0E9", new converBean("C2003C00200026D0B9370005", "A1213111"));
//        put("0088102BC12013160030E182", new converBean("C2003C00200026D13B830005", "A1246467"));
//        put("0088102BC12013160030E17C", new converBean("C2003C00200026FBE3330005", "A0041907"));
        //云南艺术学院
        put("0088102BC12013160030E176", new converBean("004300530A334230303942303930", "3B009B0905"));
        put("0088102BC12013160030E0E9", new converBean("004300530A334130333042303430", "3A030B0405"));
        put("0088102BC12013160030E182", new converBean("004300530A334130333042303630", "3A030B0605"));
    }};
    private static HashMap<String, converBean> RULE_funing = new HashMap<String, converBean>() {{
        //东华禅寺
        put("0088102BC12013160030E0E9", new converBean("00010361335D0F00000021A0", "3B009B0905"));
        put("0088102BC12013160030E176", new converBean("0001036100000000000021A0", "3A030B0405"));
        put("C2003C00200026D196F50010", new converBean("00010361335D0F00000021A0", "3A030B0605"));
    }};

    private static HashMap<String, converBean> RULE_SHANXISHIFAN = new HashMap<String, converBean>() {{
        //
        put("0088102BC12013160030E176", new converBean("004300530A334230303942303930", "3B009B0905"));
        put("0088102BC12013160030E0E9", new converBean("004300530A334130333042303430", "3A030B0405"));
        put("0088102BC12013160030E182", new converBean("004300530A334130333042303630", "3A030B0605"));
//        put("0088102BC12013160030E17C", new converBean("C2003C00200026FBE3330005", "A0041907"));
    }};






    private static HashMap<String, converBean> qiongtaishifan = new HashMap<String, converBean>() {{
        put("C20063012012F66804580805", new converBean("c226310020000adb79ea0005", "0126905"));
        put("C200630120131B1E655C0805", new converBean("c226310020000adb79eb0005", "0514604"));
        put("C200630120133C82D33E0805", new converBean("c226310020000adb79ea0005", "0947222"));
        put("C20063012012F66804580805", new converBean("c226310020000adb79eb0005", "0207224"));
        put("C20063012012F3BE5AD90805", new converBean("c226310020000adb79ea0005", "7262513"));
        put("C200630120131A3B267C0805", new converBean("c226310020000adb79eb0005", "1174808"));
        put("C20063012013181FB1BE0805", new converBean("c226310020000adb79eb0005", "7223789"));
    }};
    private static HashMap<String, converBean> shanxishifan = new HashMap<String, converBean>() {{
        put("C20063012012F66804580805", new converBean("c226310020000adb79ea0005", "0126905"));
        put("C200630120131B1E655C0805", new converBean("c226310020000adb79eb0005", "0514604"));
        put("C200630120133C82D33E0805", new converBean("c226310020000adb79ea0005", "0947222"));
        put("C20063012012F66804580805", new converBean("c226310020000adb79eb0005", "0207224"));
        put("C20063012012F3BE5AD90805", new converBean("c226310020000adb79ea0005", "7262513"));
        put("C200630120131A3B267C0805", new converBean("c226310020000adb79eb0005", "1174808"));
        put("C20063012013181FB1BE0805", new converBean("c226310020000adb79eb0005", "7223789"));
    }};

    private static HashMap<String, converBean> invengoV1 = new HashMap<String, converBean>() {{
        put("C200010020000098983C0805", new converBean("C20FAB002004CEE5A3A40805", "A1025316"));
        put("C20001002000009898340805", new converBean("C20FAB002004CEE5A3A30805", "A1025315"));
        put("C20001002000009898320805", new converBean("C20FAB002004CEE259320305", "A0809650"));
        put("C200010020000098983A0805", new converBean("C20FAB002004CEE259330805", "A0809651"));

        put("0088102BC12013160030E0E9", new converBean("C2003C00200026D196F50005", "A1269877"));
        put("0088102BC12013160030E17C", new converBean("C2003C00200026D0B9370005", "A1213111"));
        put("0088102BC12013160030E176", new converBean("C2003C00200026D13B830005", "A1246467"));
//        put("C20063012012F3BE5AD90805", new converBean("C20FAB002004CEE5A3A40805", "A1025316"));
//        put("C200630120131A3B267C0805", new converBean("C20FAB002004CEE5A3A40805", "A1025316"));
//        put("C20063012013181FB1BE0805", new converBean("C20FAB002004CEE5A3A40805", "A1025316"));
    }};


    private static HashMap<String, converBean> sddx_books = new HashMap<String, converBean>() {{
        //图书
        put("E200680A000040023B63A014", new converBean("010200A13A03485338A40100", "CB01268943"));
        put("E200680A000040023B635C14", new converBean("010200A18A03485328B80100", "CB01281708"));
        put("E200680A000040023B635814", new converBean("010200A14A0348538CC00100", "CB01287074"));
        put("E200680A0000400B1493A123", new converBean("010200A17A034853A0CC0100", "CB01294807"));
        put("E200680A0000400B1493D523", new converBean("010200A15A034853C8DE0100", "CB01306425"));
        put("E200680A0000400B1493F923", new converBean("010200A10A034853F0E20100", "CB01309080"));
        put("E200680A0000400B1493D123", new converBean("010200A15A03485368EE0100", "CB01316425"));
    }};

    private static HashMap<String, converBean> duke_books = new HashMap<String, converBean>() {{
        //图书
        put("E200680A000040023B63A014", new converBean("01045300AA04001BE8F00000", "K00015418J"));
        put("E200680A000040023B635C14", new converBean("010453009A04001BE4F00000", "K00015417I"));
        put("E200680A000040023B635814", new converBean("01045300BA04001BECF00000", "K00015419K"));
        put("E200680A0000400B1493A123", new converBean("010453003A04001BF0F00000", "K00015420C"));
        put("E200680A0000400B1493D523", new converBean("010453008A04001BE0F00000", "K00015416H"));
        put("E200680A0000400B14931123", new converBean("000400338A04001B04ED0100", "K00031553H"));
        put("E200680A0000400B1492D123", new converBean("00040033CA04001B84C00000", "K00013089L"));
        put("E200680A0000400B133D123", new converBean("410453008A04001BE0F00000", "K00015420C"));
        put("E200680A0000400B1593D123", new converBean("010453007A04001BDCF00000", "K00015419K"));
    }};


    private static HashMap<String, converBean> sddx_shelfs = new HashMap<String, converBean>() {{
        //层架
        put("E200680A000040023B63A014", new converBean("CC420800446244000810B848", "02401120401"));
        put("E200680A000040023B635C14", new converBean("CC42080054B806000390C761", "02400110101"));
    }};

    private static HashMap<String, converBean> duke_shelfs = new HashMap<String, converBean>() {{
        //层架
        put("E200680A000040023B63A014", new converBean("C20FAF00A21821F808E00009", "02401120401"));
        put("E200680A000040023sB63514", new converBean("C20FAF00A218202806E00009", "02400110101"));
        put("E200680A000040023B635C14", new converBean("C20FAF00A21821E004E00009", "02400110101"));
        put("E200680A0000wsf400235C14", new converBean("C2006300A218400804200009", "02400110101"));
        put("E200680A000340023B635C14", new converBean("C2006300A218400802200009", "02400110101"));
    }};

    private HashMap<String, String> convertCache = new HashMap<>();

    public static String convertEpc(String epc, EPCStrategy epcStrategy) {
        String newEpc = epc;
        switch (epcStrategy.getRule()) {
            case RULE_BenBu:
                newEpc = benbu.get(epc) == null ? epc : benbu.get(epc).getEpc();
                break;
            case RULE_INVENGO:
                newEpc = invengoV1.get(epc) == null ? epc : invengoV1.get(epc).getEpc();
                break;
            case RULE_COLLEGES:
                newEpc = sddx_books.get(epc) == null ? epc : sddx_books.get(epc).getEpc();
                break;
            case RULE_ShanXiShiFan:
                newEpc = RULE_SHANXISHIFAN.get(epc) == null ? epc : RULE_SHANXISHIFAN.get(epc).getEpc();
                break;
            case RULE_DUKE:
                newEpc = duke_books.get(epc) == null ? epc : duke_books.get(epc).getEpc();
                break;
            case RULE_DEFAULT:
                newEpc = RULE_Default.get(epc) == null ? epc : RULE_Default.get(epc).getEpc();
                break;
            case RULE_FuNing:
                newEpc = RULE_funing.get(epc) == null ? epc : RULE_funing.get(epc).getEpc();
                break;
        }
        return newEpc;
    }


    public static void testBooks() {
        for (String s : duke_books.keySet()) {
            try {
                Thread.sleep(300);
                KLog.e("开始解析： " + s);
                String epc = duke_books.get(s).getEpc();
                AnalyzeImpl.TO_BOOK.apply("xxx", epc, RfidModelImpl.EPC, EPCAnalyzeFactory.getInstance().getEPCStrategy(_EpcRuleTag.RULE_DUKE), "AnalyzeTestDialog");
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static void testShelfs() {
        for (String s : duke_shelfs.keySet()) {
            String epc = duke_shelfs.get(s).getEpc();
            AnalyzeImpl.TO_SHELF.apply("xxx", epc, RfidModelImpl.EPC, EPCAnalyzeFactory.getInstance().getEPCStrategy(_EpcRuleTag.RULE_DUKE), "AnalyzeTestDialog");
        }
    }

    private static class converBean {
        private String epc;
        private String barCode;

        public converBean(String epc, String barCode) {
            this.epc = epc;
            this.barCode = barCode;
        }

        public String getEpc() {
            return epc;
        }
    }
}
